package com.ymatou.iapi.productmanager.compare;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;

import com.ymatou.iapi.productmanager.compare.oldBean.ProductcataloginfoReponse;
import com.ymatou.iapi.productmanager.parameter.ProductCatalogListBean;
import com.ymatou.iapi.productmanager.parameter.QuerySellerProductListResponseBean;
import com.ymatou.iapi.productmanager.parameter.SellerProductStatisticsBean;
import com.ymatou.iapi.productmanager.parameter.appproduct.GetSellerProductListBean;
import com.ymatou.iapi.productmanager.parameter.productDesc.ProductDescriptionInfoBean;
import com.ymatou.iapi.productmanager.parameter.productExistsActivity.CheckProductInActivityResp;
import com.ymatou.iapi.productmanager.parameter.productdetail.ProductAndCatalogInfoBean;
import com.ymatou.iapi.productmanager.parameter.violateRemarks.ProductViolateRemarksBean;
import com.ymttest.utils.FileUtil;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.compare.CompareHelper;
import com.ymttest.utils.compare.CompareManager;
import com.ymttest.utils.compare.LogPathConf;
import com.ymttest.utils.compare.LoggerHelper;
import com.ymttest.utils.compare.LoggerInterface;

public class MainCompare {

	public static void compareQuerySellerProductListCall() {
		// config
		LogPathConf logPathConf = new LogPathConf(true);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		CompareHelper compareHelper = new CompareHelper(logger, 5);

		// data
		String userAndProductId = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";

		List<String> productsFromFile = FileUtil.readFileAsLine(userAndProductId);

		List<Map<String, Object>> paramMapList = new ArrayList<>();
		productsFromFile.forEach(ele -> {
			String[] param = ele.split(",");
			paramMapList.add(MapUtil.hashMap("sellerId", param[0], "productId", param[1]));
		});

		compareHelper.setCompareApiData(SearchCompareAPI.old_QuerySellerProductListCall, SearchCompareAPI.oldTimeFormat,
				SearchCompareAPI.new_QuerySellerProductListCall, SearchCompareAPI.newTimeFormat, paramMapList,
				QuerySellerProductListResponseBean.class,
				(x, y) -> BeanHelper.oldQuerySellerProductListResponseBeanHandler(x, y));

		compareHelper.startCompare();

	}
	
	public static void compareGetProductCatalogInfos(){
		LogPathConf logPathConf = new LogPathConf(true);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		CompareHelper compareHelper = new CompareHelper(logger, 5);
		
		
		String userAndProductId = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";

		List<String> productsFromFile = FileUtil.readFileAsLine(userAndProductId);
		
		List<Map<String, Object>> paramMapList = new ArrayList<>();
		productsFromFile.forEach(ele -> {
			String[] param = ele.split(",");
			paramMapList.add(MapUtil.hashMap("userId", param[0], "productId", param[1]));
		});

		compareHelper.setCompareApiData(SearchCompareAPI.old_GetProductCatalogListCall, SearchCompareAPI.oldTimeFormat,
				SearchCompareAPI.new_GetProductCatalogListCall, SearchCompareAPI.newTimeFormat, paramMapList,
				ProductCatalogListBean.class,
				(x, y) -> BeanHelper.oldProductCatalogListBeanHandler(x, y));

		compareHelper.startCompare();
	}
	
	public static void compareGetProductCatalogInfos2(){
		LogPathConf logPathConf = new LogPathConf(true);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		CompareHelper compareHelper = new CompareHelper(logger, 5);
		
		
		String userAndProductId = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";

		List<String> productsFromFile = FileUtil.readFileAsLine(userAndProductId);
		
		List<Map<String, Object>> paramMapList = new ArrayList<>();
		productsFromFile.forEach(ele -> {
			String[] param = ele.split(",");
			paramMapList.add(MapUtil.hashMap("userId", param[0], "productId", param[1]));
		});

		compareHelper.setCompareApiData(SearchCompareAPI.old_GetProductCatalogListCall, SearchCompareAPI.oldTimeFormat,
				SearchCompareAPI.oldToNew_GetProductCatalogListCall, SearchCompareAPI.oldTimeFormat, paramMapList,
				ProductcataloginfoReponse.class,
				null);

		compareHelper.startCompare();
	}
	
	public static void compareGetProductAndCatalogInfo(){
		LogPathConf logPathConf = new LogPathConf(true);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		CompareHelper compareHelper = new CompareHelper(logger, 5);
		
		
		String userAndProductId = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";

		List<String> productsFromFile = FileUtil.readFileAsLine(userAndProductId);
		
		List<Map<String, Object>> paramMapList = new ArrayList<>();
		productsFromFile.forEach(ele -> {
			String[] param = ele.split(",");
			paramMapList.add(MapUtil.hashMap("UserId", param[0], "ProductId", param[1]));
		});

		compareHelper.setCompareApiData(SearchCompareAPI.old_GetProductAndCatalogInfoCall, SearchCompareAPI.oldTimeFormat,
				SearchCompareAPI.new_GetProductAndCatalogInfoCall, SearchCompareAPI.newTimeFormat, paramMapList,
				ProductAndCatalogInfoBean.class,
				(x, y) -> BeanHelper.oldProductAndCatalogInfoBeanHandler(x, y));

		compareHelper.startCompare();
	}
	
	public static void compareCheckProductExistsActivity(){
		LogPathConf logPathConf = new LogPathConf(true);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		CompareHelper compareHelper = new CompareHelper(logger, 5);
		
		
		String userAndProductId = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";

		List<String> productsFromFile = FileUtil.readFileAsLine(userAndProductId);
		
		List<Map<String, Object>> paramMapList = new ArrayList<>();
		productsFromFile.forEach(ele -> {
			String[] param = ele.split(",");
			paramMapList.add(MapUtil.hashMap("UserId", param[0], "ProductId", param[1]));
		});

		compareHelper.setCompareApiData(SearchCompareAPI.old_CheckProductExistsActivityCall, SearchCompareAPI.oldTimeFormat,
				SearchCompareAPI.oldToNew_CheckProductExistsActivityCall, SearchCompareAPI.newTimeFormat, paramMapList,
				CheckProductInActivityResp.class,
				null);

		compareHelper.startCompare();
	}
	
	
	
	public static void compareGetProductViolateRemarksCall() {
		String paramsFilePath = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";
		
		CompareManager.compareApiCall(5, true, paramsFilePath, 
				x->MapUtil.hashMap("productId", x[1]), 
				SearchCompareAPI.old_GetProductViolateRemarksCall, SearchCompareAPI.oldTimeFormat, 
				SearchCompareAPI.new_GetProductViolateRemarksCall, SearchCompareAPI.newTimeFormat, 
				ProductViolateRemarksBean.class, null);
		
	}
	
	
	
	
	
	
	public static void compareGetSellerProductListCall() {
		String paramsFilePath = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId_productId.txt";
		
		CompareManager.compareApiCall(5, false, paramsFilePath, 
				x->MapUtil.hashMap("SellerId", x[0], "ProductIdList", new JSONArray(Arrays.asList(x[1]))), 
				SearchCompareAPI.old_GetSellerProductListCall, SearchCompareAPI.newTimeFormat, 
				SearchCompareAPI.new_GetSellerProductListCall, SearchCompareAPI.newTimeFormat, 
				GetSellerProductListBean.class, null);
		
	}
	
	
	
	public static void compareGetNewProductDescriptionInfoCall() {
		String paramsFilePath = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "productId.txt";
		
		CompareManager.compareApiCall(paramsFilePath, 
				x->MapUtil.hashMap("UserId", "111", "ProductId", x[0]), 
				SearchCompareAPI.old_GetNewProductDescriptionInfoCall, 
				SearchCompareAPI.new_GetNewProductDescriptionInfoCall, 
				ProductDescriptionInfoBean.class);
		
	}
	
	
	public static void compareQuerySellerProductStatistics() {
		String paramsFilePath = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+ "CompareData" + File.separator + "userId.txt";
		
		CompareManager.compareApiCall(paramsFilePath, 
				x->MapUtil.hashMap("SellerId", x[0]), 
				SearchCompareAPI.old_QuerySellerProductStatistics, 
				SearchCompareAPI.new_QuerySellerProductStatistics, 
				SellerProductStatisticsBean.class);
		
	}
	
	
	public static void main(String args[]) {
		compareGetNewProductDescriptionInfoCall();
	
		
		
		
		
		
		
		
		
		//compareGetProductViolateRemarksCall();
		
		
	/*	
		String num = "5";
		if (args.length>0){
			num = args[0];
		}
		
		System.out.println(num);
		
		if (num.equals("1")){
			compareQuerySellerProductListCall();
		}
		
		if (num.equals("2")){
			compareGetProductCatalogInfos();
		}
		
		if (num.equals("3")){
			compareGetProductAndCatalogInfo();
		}
		
		if (num.equals("4")){
			compareGetProductCatalogInfos2();
		}
		
		if (num.equals("5")){
			compareGetProductCatalogInfos2();
			compareCheckProductExistsActivity();
		}
		*/
	}
}
